package com.atgm.mall.gmmailorder.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.atgm.mall.gmmailorder.vo.req.OrderReqVo;
import com.atgm.mall.gmmailorder.vo.resp.OrderDetailRespVo;
import com.atgm.mall.gmmailorder.vo.resp.OrderItemRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atgm.mall.gmmailorder.entity.OrderEntity;
import com.atgm.mall.gmmailorder.service.OrderService;
import com.atgm.common.utils.PageUtils;
import com.atgm.common.utils.R;


/**
 * 订单
 *
 * @author pdx
 * @email 945097967@qq.com
 * @date 2021-08-20 10:06:51
 */
@RestController
@RequestMapping("gmmallorder/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 获取订单确认页面数据
     *
     * @param gameIds
     * @return
     */
    @GetMapping("/getOrderConfirm")
    public R getOrderConfirm(@RequestParam("gameIds") List<Long> gameIds) {
        OrderItemRespVo orderItemRespVo = orderService.handlerOrerConfirm(gameIds);
        return R.ok().setData(orderItemRespVo);
    }

    /**
     * 提交订单
     *
     * @param orderReqVo
     * @return
     */
    @PostMapping("/submitOrder")
    public R submitOrder(@RequestBody OrderReqVo orderReqVo) {
        String orderSn = orderService.submitOrderInfo(orderReqVo);
        return R.ok().setData(orderSn);
    }

    @GetMapping("/getOrderList")
    public R getOrderList(@RequestParam("status") Integer status) {
        List<OrderDetailRespVo> list = orderService.queryOrderList(status);
        return R.ok().setData(list);
    }

    @GetMapping("/getOrder/{orderSn}")
    public R getOrderInfo(@PathVariable("orderSn") String orderSn) {
        OrderDetailRespVo orderDetailRespVo = orderService.queryOrderInfo(orderSn);
        return R.ok().setData(orderDetailRespVo);
    }

    @GetMapping("/getPrice/{orderSn}")
    public R getPrice(@PathVariable("orderSn") String orderSn) {
        BigDecimal price = orderService.queryPriceByOrderSn(orderSn);
        return R.ok().setData(price);
    }

    @GetMapping("/updateStatus/{orderSn}/{status}")
    public R updateStatus(@PathVariable("orderSn") String orderSn, @PathVariable("status") Integer status) {
        orderService.updateStatusInfo(orderSn, status);
        return R.ok();
    }

//    @GetMapping(value = "/status/{orderSn}")
//    public R getOrderStatus(@PathVariable("orderSn") String orderSn) {
//        OrderEntity orderEntity = orderService.getOrderByOrderSn(orderSn);
//        return R.ok().setData(orderEntity);
//    }

}
